<template>
	<view class="k1" v-for="(v,i) in showData">
		<view class="k">
			<view>
				<text>{{v.s_people}}</text>
				<text>{{v.s_tel}}</text>
			</view>
			<view>
				<navigator open-type="navigate" url="./bianjidizhi">
					<text class="iconfont icon-yijianfankui" @click="tiao(i)"></text>
				</navigator>
				<text class="iconfont icon-shanchu" @click="del(v.s_id)"></text>
			</view>
		</view>
		<view class="b">{{v.s_dizhi}}</view>
		<switch name="switch" :checked="v.s_isMoren==1?true:false" @change="change" @click="click(v.s_id)" />默认地址
	</view>
	<navigator url="./xinjiandizhi" open-type="navigate">
		<view class="tian">+ 添加地址</view>
	</navigator>

</template>

<script>
	import {
		toRefs,
		onMounted,
		reactive,
		computed
	} from 'vue'

	import store from '../../store/index.js'
	import http from '../../utils/http.js'

	export default {
		setup() {

			let data = reactive({
				showData: [],
				b: 2,
				ismoren: '',
				id: '',
				tiao: (a) => {
					store.state.dizhi.a = data.showData[a]
				},
				click: (a) => {
					data.id = a
					// console.log(data.id)
				},

				change: (e) => {
					if (e.detail.value) {
						data.ismoren = 1
					} else {
						data.ismoren = 0
					}
					setTimeout(() => {
						http({
							url: '/SetBasic/xiugaizhuangtai',
							method: 'post',
							data: {
								ismoren: data.ismoren,
								id: data.id
							}
						}).then((res) => {
							console.log(res)
						})
						uni.redirectTo({
							url: '../mine/dizhiguanli'
						})
					}, 300)
				},
				del: (a) => {
					http({
						url: '/SetBasic/deldizhi',
						method: 'post',
						data: {
							id: a
						}
					}).then((res) => {
						console.log(res)
						uni.showToast({
							title: '删除成功',
							duration: 1500
						})
						uni.redirectTo({
							url: '../mine/dizhiguanli'
						})
					})
				}
			})
			return {
				...toRefs(data),
			}
		},
		onShow: function() {
			// console.log(store.state.userID)
			http({
				url: '/SetBasic/dizhiall',
				method: 'get',
				data:{
					id:store.state.userID
				}
			}).then((res) => {
				this.showData = res.data.data
			})
		}
	}
</script>

<style lang="less">
	@import url("~@/static/fonts/iconfont.css");

	.k1 {
		border: 1rpx solid #F2F2F2;
		border-radius: 10rpx;
		margin: 20rpx 35rpx;
		padding: 35rpx 30rpx;
	}

	.k {
		display: flex;
		justify-content: space-between;

		view {
			text {
				&:nth-child(1) {
					margin-right: 35rpx;
				}
			}
		}

		>view:nth-child(2) {
			display: flex;
		}
	}

	.b {
		color: #9D9D9D;
		margin: 30rpx 0;
	}

	.tian {
		font-size: 45rpx;
		text-align: center;
		margin: 30rpx;
	}
</style>
